<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Order;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class OrderController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Order(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('order_sn','订单号');
            $grid->column('trade_no','流水号');
            $grid->column('uid','用户名');
            $grid->column('phone','手机号');
            $grid->column('order_type','订单类型');
            $grid->column('pay_price','支付金额');
            $grid->column('pay_type','支付方式')->display(function ($display){
                if ($display==1){
                    return '支付宝';
                }else{
                    return  '微信';
                }
            });
            $grid->column('pay_status','支付状态')->display(function ($display){
                if ($display==1){
                    return '已支付';
                }else{
                    return  '未支付';
                }
            });
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Order(), function (Show $show) {
            $show->field('id');
            $show->field('order_sn','订单号');
            $show->field('trade_no','流水号');
            $show->field('uid','用户名');
            $show->field('phone','手机号');
            $show->field('order_type','订单类型');
            $show->field('pay_price','支付金额');
            $show->field('pay_type','支付金额')->as(function ($as){
                if ($as==1){
                    return '支付宝';
                }else{
                    return  '微信';
                }
            });;
            $show->field('pay_status','支付状态')->as(function ($as){
                if ($as==1){
                    return '已支付';
                }else{
                    return  '未支付';
                }
            });
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Order(), function (Form $form) {
            $form->display('id');
            $form->text('order_sn','订单号');
            $form->text('trade_no','流水号');
            $form->text('uid','用户名');
            $form->text('phone','手机号');
            $form->text('order_type','订单类型');
            $form->text('pay_price','支付金额');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
